import { SharedService } from './shared.service'
import { Global, Module, ValidationPipe } from '@nestjs/common'
import { TypeOrmModule } from '@nestjs/typeorm'
import { RedisModule } from '@nestjs-modules/ioredis'
import { JwtAuthGuard } from 'src/common/guards/jwt-auth'
import { APP_GUARD, APP_INTERCEPTOR, APP_FILTER } from '@nestjs/core'
import { ReponseTransformInterceptor } from 'src/common/interceptors/reponse-transform.interceptor'
import { AllExceptionsFilter } from 'src/common/filter/all-exception.filter'
@Global()
@Module({
  imports: [
    TypeOrmModule.forRoot({
      autoLoadEntities: true,
      type: 'mysql',
      host: 'localhost',
      port: 3306,
      username: 'root',
      password: '123456',
      database: 'xktest',
      synchronize: true,
    }),
    RedisModule.forRoot({
      type: 'single',
      url: 'redis://localhost:6379',
    }),
  ],
  controllers: [],
  providers: [
    SharedService,
    //jwt守卫
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
    /* 全局返回值转化拦截器 */
    {
      provide: APP_INTERCEPTOR,
      useClass: ReponseTransformInterceptor,
    },
    {
      provide: APP_FILTER,
      useClass: AllExceptionsFilter,
    },
  ],
  exports: [SharedService],
})
export class SharedModule {}
